home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 49 / Amiga Format CD49 (2000-01-17)(Future Publishing)(GB)(Track 1 of 3)[!][issue 2000-02].iso / -serious- / graphics / amicad / arexx_english / savenets.amicad < prev    next >
Text File  |  1999-12-06  |  11KB  |  418 lines

  1. /* Élaboration d'une netlist, appel simulateur analogique Spice
  2.    $VER: SaveNets 1.02e (© R.Florac, 22/05/99) */
  3.  
  4. options results     /* indispensable pour récupérer le résultat des macros */
  5.  
  6. signal on error     /* pour l'interception des erreurs */
  7. signal on syntax
  8.  
  9. /* Test des liaisons */
  10. j=1; nets=1;
  11. 'DEF NEXTJUNCTION(O)=OO=O:WHILE(IF(OO>0,TYPE(OO)<>7,0),IF(OO<OBJECTS(-1),OO=OO+1,OO=0)):OO'
  12. 'INIT(O,OO,I,X,V0,V1,B):UNMARK(-1):LOCK(-1):OBJECTS(-1)'; objets=result
  13. /* Tableaux de données:
  14. equi: une donnée par élément, donne l'indice de l'équipotentielle à laquelle est liée une ligne
  15. label: une donnée par équipotentielle, donne son nom */
  16. equi.=-1
  17. label.=""
  18.  
  19. 'TITLE("Reading labels...")'
  20. do i=1 to objets
  21.     'TYPE(O='i')'
  22.     if result=4 | result=12 | result=11 then do
  23.     'ABS(FINDLINE(1,COL(O),LINE(O)))'; j=result
  24.     if j>0 then do
  25.         'READTEXT(O)'; label=result
  26.         if datatype(label,"w") then do      /* signale les labels numériques existants */
  27.         label.label="LABEL_DÉJÀ_UTILISÉ"
  28.         end
  29.     end
  30.     end
  31. end
  32.  
  33. 'TITLE("Testing nets...")'
  34. i=1
  35. do while i>0
  36.     'OO=FINDOBJ('i',2,-1,-1)'; i=result
  37.     if result>0 then do
  38.     'TEST(OO)'
  39.     if result=0 then do
  40.         do while label.nets~=""
  41.         nets=nets+1
  42.         end
  43.         label.nets=nets
  44.         equi.i=nets
  45.         'COORDS(OO)'            /* Marquage du fil */
  46.         parse var result x0','y0','x1','y1
  47.         call test_ligne(x0,y0,nets,objets)
  48.         call test_ligne(x1,y1,nets,objets)
  49.     end
  50.     if i=objets then i=0
  51.     else i=i+1
  52.     end
  53. end
  54.  
  55. 'TITLE("Testing junctions...")'
  56. i=1
  57. do while i>0
  58.     'I=FINDOBJ('i',7,-1,-1)'; i=result
  59.     if i>0 then do
  60.     'MARK(I):L1=ABS(FINDLINE(1,COL(I),LINE(I)))'; l1=result
  61.     if l1>0 & l1<objets then do
  62.         j=l1+1
  63.         do while j>0
  64.         'J=ABS(FINDLINE('j',COL(I),LINE(I)))'; j=result
  65.         if j>0 then do
  66.             if equi.j~=equi.l1 then do
  67.             call changer_labels(l1,j)
  68.             end
  69.             if j=objets then j=0
  70.             else j=j+1
  71.         end
  72.         end
  73.     end
  74.     if i=objets then i=0
  75.     else i=i+1
  76.     end
  77. end
  78.  
  79. 'TITLE("Looking for labels and connectors...")'
  80. do i=1 to objets
  81.     'TYPE(O='i')'
  82.     if result=4 | result=12 | result=11 then do
  83.     'ABS(FINDLINE(1,COL(O),LINE(O)))'; j=result
  84.     if j>0 then do
  85.         net=equi.j
  86.         'READTEXT(O)'; label=result
  87.         label.net=label
  88.     end
  89.     end
  90. end
  91.  
  92. 'TITLE("Looking for powers...")'
  93. do i=1 to objets
  94.     'FINDPART('i',"POWER SUPPLY")'; i=result
  95.     if i>0 then do
  96.     j=connexion_broche(i,1)
  97.     if j>0 then do
  98.         net=equi.j
  99.         'READTEXT(GETVAL('i'))'; label=result
  100.         label.net=label
  101.     end
  102.     end
  103.     else leave
  104. end
  105.  
  106. 'TITLE("Testing redundances...")'
  107. do i=1 to nets
  108.     do j=i+1 to nets
  109.     if label.j~="" then do
  110.         if label.i=label.j then do
  111.         do k=1 to objets
  112.             if equi.k=j then equi.k=i
  113.         end
  114.         label.j=""
  115.         end
  116.     end
  117.     end
  118. end
  119.  
  120. 'TITLE("Looking for grounds...")'
  121. do i=1 to objets
  122.     'FINDPART('i',"GROUND")'; i=result
  123.     if i>0 then do
  124.     j=connexion_broche(i,1)
  125.     if j>0 then do
  126.         equi.0=0; label.0=0
  127.         call changer_labels(0,j)
  128.     end
  129.     end
  130.     else leave
  131. end
  132.  
  133. do until c=0
  134.     'TITLE("Setting netlist ended"):SELECT("Choose an action"+CHR(10)+"Look for nets"+CHR(10)+"Check netlist"+CHR(10)+"Save netlist"+CHR(10)+"Abort script")'
  135.     select
  136.     when result=1 then call visu_equi
  137.     when result=2 then call controler_netlist
  138.     when result=3 then call sauver_netlist
  139.     otherwise c=0
  140.     end
  141. end
  142. 'UNLOCK(-1):INIT(O,OO,I,X,V0,V1,B)'
  143. exit
  144.  
  145. visu_equi:
  146.     'TITLE("Looking for nets"):UNMARK(-1)'
  147.     do i=0 to nets
  148.     if label.i ~= "LABEL_DÉJÀ_UTILISÉ" & label.i ~= "" then do
  149.         do j=1 to objets
  150.         if equi.j=i then 'MARK('j')'
  151.         end
  152.         'SELECT("Net 'label.i'"+CHR(10)+"Abort"+CHR(10)+"Continue"+CHR(10)+"Save netlist"+CHR(10)+"Check netlist")'
  153.         if result <= 1 then return
  154.         if result = 3 then do
  155.         call sauver_netlist
  156.         'UNLOCK(-1):INIT(O,OO,I,X,V0,V1,B)'
  157.         exit
  158.         end
  159.         if result = 4 then do
  160.         call controler_netlist
  161.         leave
  162.         end
  163.         'UNMARK(-1)'
  164.     end
  165.     end
  166.     return
  167.  
  168. test_ligne: procedure expose equi.
  169.     parse arg x0,y0,n,nbo
  170.     o=1
  171.     do until o=0
  172.     'X=FINDOBJ('o',2,'x0','y0')'; o=result
  173.     if o>0 then do
  174.         'IF(TEST(X),"",MARK(X):COORDS(X))'
  175.         if result~="" then do
  176.         parse var result x1','y1','x2','y2
  177.         equi.o=n
  178.         if x0=x1 & y0=y1 then call test_ligne(x2,y2,n,nbo)
  179.         else call test_ligne(x1,y1,n,nbo)
  180.         end
  181.         if o=nbo then o=0
  182.         else o=o+1
  183.     end
  184.     end
  185.     return
  186.  
  187. changer_labels: procedure expose equi. objets label.
  188.     parse arg o1,o2
  189.     if datatype(equi.o2,'w') then do
  190.     e=equi.o2
  191.     label.e=""
  192.     do i=1 to objets
  193.         if equi.i=e then equi.i=equi.o1
  194.     end
  195.     return o1
  196.     end
  197.     else do
  198.     e=equi.o1
  199.     label.e=""
  200.     do i=1 to objets
  201.         if equi.i=e then equi.i=equi.o2
  202.     end
  203.     return o2
  204.     end
  205.     return
  206.  
  207. test_jonction: procedure expose equi.
  208.     parse arg xj,yj,n,objets
  209.     obj=1
  210.     do while obj>0
  211.     'X=ABS(FINDLINE('obj','xj','yj'))'; obj=result
  212.     if obj>0 then do
  213.         if equi.obj=n then return 1
  214.         if obj=objets then return 0
  215.         obj=obj+1
  216.     end
  217.     end
  218.     return 0
  219.  
  220. controler_netlist:
  221.     'TITLE("Checking netlist...")'
  222.     i=1
  223.     do while i>0
  224.     'O=FINDOBJ('i',1,-1,-1)'; i=result
  225.     if i>0 then do
  226.         'PARTNAME(O)'
  227.         if result~="POWER SUPPLY" & result ~="GROUND" then do
  228.         'IF(GETREF(O),READTEXT(GETREF(O)),PARTNAME(O)+"?")'
  229.         ligne=translate(result,"_"," ")||' '
  230.         'DEVPINS(O)'; j=result
  231.         do k=1 to j
  232.             l=connexion_broche(i,k)
  233.             if l>0 then do
  234.             net=equi.l
  235.             ligne=ligne||label.net||' '
  236.             end
  237.             else ligne=ligne||"-1"||' '
  238.         end
  239.         'IF(GETVAL(O),READTEXT(GETVAL(O)),PARTNAME(O))'
  240.         ligne=ligne||result
  241.         'UNMARK(-1):MARK(O):SELECT("'ligne'"+CHR(10)+"Continuer"+CHR(10)+"Abandonner")'
  242.         if result~=1 then return
  243.         end
  244.         if i=objets then leave
  245.         i=i+1
  246.     end
  247.     end
  248.     'TITLE("")'
  249. return
  250.  
  251. sauver_netlist:
  252.     'TITLE(""):REQFILE("Netlist file to create","Spice",FILEPART("")+".cir")'
  253.     fichier=result
  254.     if fichier="" then return
  255.     'TITLE("Saving netlist...")'
  256.     if ~open(file, fichier, 'W') then return
  257.     'FILEPART("")'
  258.     writeln(file,result)
  259.     'DATE(1)+" à "+TIME(1)'
  260.     writeln(file,"* Created by AmiCAD, on "||result||" *")
  261.     writeln(file,".include Work:Spice3f5/lib/modeles.cir")
  262.     do i=1 to objets
  263.     'O=FINDOBJ('i',1,-1,-1)'; i=result
  264.     if result>0 then do
  265.         'PARTNAME(O)'
  266.         if result~="POWER SUPPLY" & result ~="GROUND" then do
  267.         'IF(GETREF(O),READTEXT(GETREF(O)),PARTNAME(O)+"?")'
  268.         ligne=translate(result,"_"," ")||' '
  269.         'DEVPINS(O)'; j=result
  270.         do k=1 to j
  271.             l=connexion_broche(i,k)
  272.             if l>0 then do
  273.             net=equi.l
  274.             ligne=ligne||label.net||' '
  275.             end
  276.             else ligne=ligne||"-1"||' '
  277.         end
  278.         'IF(GETVAL(O),READTEXT(GETVAL(O)),PARTNAME(O))'
  279.         ligne=ligne||result
  280.         call writeln(file, ligne)
  281.         end
  282.     end
  283.     else leave i
  284.     end
  285.     analyse=""
  286.     do i=1 to objets
  287.     'FINDOBJ('i',4,-1,-1)'; i=result
  288.     if i>0 then do
  289.         'READTEXT('i')'; t=result
  290.         if left(t,10)=".ANALYSE: " then do
  291.         analyse=substr(t,11)
  292.         end
  293.     end
  294.     else leave
  295.     end
  296.     if analyse="" then do
  297.     'SELECT("Type of analyse to do"+CHR(10)+"AC"+CHR(10)+"DC"+CHR(10)+"Transient")'
  298.     select
  299.         when result=1 then do
  300.         'SELECT("Type of variation"+CHR(10)+"Decade"+CHR(10)+"Octave"+CHR(10)+"Linear")'
  301.         select
  302.             when result=1 then do
  303.             f="DEC "; v="by decade"
  304.             end
  305.             when result=2 then do
  306.             f="OCT "; v="by octave"
  307.             end
  308.             when result=3 then do
  309.             f="LIN "; v="of test"
  310.             end
  311.             otherwise do
  312.             close(file)
  313.             return
  314.             end
  315.         end
  316.         'ASKNUM("Number of points 'v'?",100)'
  317.         f=f||result
  318.         'ASK("What''s the begining frequency?", "1")'
  319.         f=f||" "||result
  320.         'ASKTEXT("What''s the ending frequency?","100")'
  321.         analyse="AC "||f||' '||result
  322.         end
  323.         when result=2 then do
  324.         'UNMARK(-1):MESSAGE("You have to"+CHR(10)+"select a source")'
  325.         'PICKOBJ("Select the source to be swept.")'
  326.         f=result
  327.         if f<1 then return
  328.         'MARK('f'):TYPE('f')'
  329.         if result=5 then 'READTEXT('f')'
  330.         else 'READTEXT(GETREF('f'))'
  331.         f=result
  332.         'V0=ASKTEXT("What''s the start value?","V")'
  333.         f=f||' '||result
  334.         'V1=ASKTEXT("What''s the ending value?","V")'
  335.         f=f||' '||result
  336.         'ASKTEXT("What''s the increment value?",STR((VAL(V1)-VAL(V0))/100)+"V")'
  337.         analyse="DC "||f||' '||result
  338.         end
  339.         when result=3 then do
  340.         'ASKTEXT("Simulation time ?","s")'; temps=result
  341.         'ASKTEXT("Simulation step ?","s")'; pas=result
  342.         'ASKTEXT("Time to begin simulation?","s")'; d=result
  343.         analyse="tran "||pas||" "||temps||" "||d
  344.         end
  345.         otherwise
  346.         return
  347.     end
  348.     end
  349.     if analyse~="" then writeln(file,"."||analyse)
  350.     i=1
  351.     s=''
  352.     'UNMARK(-1):MESSAGE("You can select"+CHR(10)+"the signals to display"+CHR(10)+"Click on the right"+CHR(10)+"button to stop")'
  353.     do while i>0
  354.     'PICKOBJ("Select a signal (label or net)")'
  355.     i=result
  356.     if i>0 then do
  357.         'MARK('i'):TYPE('i')'; t=result
  358.         if t=2 then do
  359.         lab=equi.i
  360.         lab=label.lab
  361.         end
  362.         else do
  363.         'READTEXT('i')'
  364.         lab=result
  365.         end
  366.         if i>0 then s=s||' '||'V('||lab||')'
  367.     end
  368.     end
  369.     if s~='' then writeln(file,".save"||s)
  370.     writeln(file,".END")
  371.     close(file)
  372.     'TITLE(""):REQUEST("Saving ended"+CHR(10)+"Do you want to do"+CHR(10)+"the simulation?")'
  373.     if result=1 then do
  374.     'SELFILE("Trace "+FILEPART(""))'
  375.     ft=result
  376.     if ft<0 then do
  377.         'NEW("Trace "+FILEPART(""))'
  378.         if result=0 then do
  379.         'MESSAGE("Opening trace window impossible")'
  380.         return
  381.         end
  382.         'SELSHEET(-1)'; ft=result
  383.     end
  384.     call 'Work:AmiCAD/ARexx/Simulation.AmiCAD' fichier
  385.     call 'Work:AmiCAD/ARexx/TracerSpice.AmiCAD' 'RAM:'||ParseFileName(fichier)||'_spice'
  386.     end
  387. return
  388.  
  389. connexion_broche: procedure
  390.     parse arg objet,broche
  391.     'PINCOL(O='objet',B='broche')'; xj=result
  392.     'PINLINE(O,B)'; yj=result
  393.     'FINDOBJ(1,2,'xj','yj')'; xl=result     /* Il y a t'il une ligne qui part de la broche? */
  394.     if xl>0 then return xl
  395.     'FINDLINE(1,'xj','yj')'; xl=result      /* Il y a peut être une ligne qui passe sur la broche... */
  396.     if xl<=0 then return 0
  397.     'FINDOBJ(1,7,'xj','yj')'                /* Il doit alors y avoir une jonction */
  398.     if result>0 then return xl
  399.     return 0
  400.  
  401. ParseFileName: procedure
  402.     parse arg FilePath, Part
  403.     DivPos = max(lastpos(':',FilePath),lastpos('/',FilePath))+1
  404.     if abbrev('FILE', upper(Part))
  405.     then return substr(FilePath, DivPos)
  406.     else
  407.     return strip(left(FilePath, DivPos-1),'T','/')
  408.  
  409. /* Traitement des erreurs, interruption du programme */
  410. syntax:
  411. erreur=RC
  412. 'MESSAGE("Script SaveNets.AmiCAD"+CHR(10)+"Erreur de syntaxe"+CHR(10)+"en ligne 'SIGL'"+CHR(10)+"'errortext(erreur)'"):UNLOCK(-1):INIT(O,OO,I,X,V0,V1,B)'
  413. exit
  414.  
  415. error:
  416. 'MESSAGE("Script SaveNets.AmiCAD"+CHR(10)+"Erreur en ligne 'SIGL'"):UNLOCK(-1):INIT(O,OO,I,X,V0,V1,B)'
  417. exit
  418.